package exam.day37;

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int INF = 0x3f3f3f3f;
        int[][] arr = new int[n + 2][m + 2];
        for(int i = 0; i < n + 2; i++) {
            arr[i][0] = arr[i][m + 1] = -INF;
        }
        for(int j = 0; j < m + 2; j++) {
            arr[0][j] = arr[n + 1][j] = -INF;
        }
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= m; j++) {
                arr[i][j] = in.nextInt();
            }
        }
        int[][] dp = new int[n + 2][m + 2];
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= m; j++) {
                dp[i][j] = 1;
            }
        }
        int max = 0;
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= m; j++) {
                if(arr[i - 1][j] > arr[i][j]) {
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j] + 1);
                }
                if(arr[i + 1][j] > arr[i][j]) {
                    dp[i][j] = Math.max(dp[i][j], dp[i + 1][j] + 1);
                }
                if(arr[i][j - 1] > arr[i][j]) {
                    dp[i][j] = Math.max(dp[i][j], dp[i][j - 1] + 1);
                }
                if(arr[i][j + 1] > arr[i][j]) {
                    dp[i][j] = Math.max(dp[i][j], dp[i][j + 1] + 1);
                }
                max = Math.max(max, dp[i][j]);
            }
        }
        System.out.println(max);
    }
}
